<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
  <head>
  <base target="_self"/>
  
  <title>发起流程</title>
  	<%@ include file="../jslib/jquerylib.jsp" %> 
	<link rel="stylesheet" type="text/css" href="<%=path %>/web/style/layout.css" />
    <script type="text/javascript" src="<%=path %>/jslib/jquery.validate.min.js"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js"  defer="defer"></script>
    <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/additional-methods.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/demo.css" />
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
	<script type="text/javascript" src="<%=request.getContextPath() %>/junyans/junyans.js"></script>

    <c:if test="${requestScope.message!=null}">
		<script type="text/javascript">
 	 		     alert('<c:out value="${requestScope.message}"></c:out>');
 	 		     window.close();
 		</script>
	</c:if> 
    <script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var stateValue="";
    $().ready(function(){
		//保存
	  	var options = {
		  	    url:'<%=request.getContextPath() %>/junyansAction!saveJunyans.action',
		  	    dataType:'json',
		  	    success: function(data) {
		  	      if(data.result=='success'){
		  	         document.getElementById("junyansid").value = data.junyansid;
					 alert("添加成功");
					 //api.close();
					 W.refreshIt();
		  	      }
		  	    }}; 
	  	
        //提交  
		var optionssubmit = {
	  	    url:'<%=request.getContextPath() %>/junyansAction!submitJunyans.action',
	  	    dataType:'json',
	  	    success: function(data) {
	  	      if(data.result=='success'){
				alert("提交成功");
				api.close();
				W.refreshIt();
	  	      }
	  	    }};
	  	    
	  	//保存
	  	$('#saveBtn').click(function(){
	  		  if(!checking()){
		    	return false;
		      }
	  	  	  $('#pageFrom').ajaxSubmit(options);
    	 });
    	 
    	//提交
		$('#submitBtn').click(function(){
			if(!confirm("是否确认提交 ？")){
		   			return false;
			}
		    if(!checking()){
		    	return false;
		    }
		    //判断样品和检测项目是否为空
		    var shejisIds = $("#gridTableShejis").jqGrid('getDataIDs')+"";
		    if(!shejisIds){
		       alert("请添加设计室人员!");
		       return false;
		    }
		    
		    var itemIds = $("#gridTableItem").jqGrid('getDataIDs')+"";
		    if(itemIds==''){
		       alert("请添加测试项目!");
		       return false;
		    }
			
			//获得下级角色
			var stepid = "";
			var stepttext = document.getElementById("steptype0");
			if (stepttext!=undefined){
				stepid=stepttext.value;
			}
			var params = {
				"flowid" : "${flowid}",
				"steptype" : stepid+""
			};
			$.ajax({
					type: "POST",
					data : params,
					async: false,//取消异步提交
					url: '<%=request.getContextPath() %>/junyansAction!getNextSteptRoles.action',
					dataType: "json",
					success : function(data, textStatus) {  
						if(data.result=='success'){	
						    var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp?roleid="+data.roles, window, "dialogWidth:930px;status:no;dialogHeight:500px");	
						    if (users != null&&users.length>0) {
				   		    var userIds = [];
				            var userNames = [];
				            	for(var i=0;i<users.length;i++){
					               userIds.push(users[i]['userid']);
					               userNames.push(users[i]['username']);
					            }
								document.getElementById("nextUserIds").value = ","+userIds+",";
								document.getElementById("nextUserNames").value = userNames;
							    $('#pageFrom').ajaxSubmit(optionssubmit);			
				            }		
						}else{
							alert(data.result)
						}
					}
			});
    	 });
    	 
    	$('#closeBtn').click(function(){
    		api.close();
		});
		
	});
	
   function checking(){
		var renwubh = $("#renwubh").val();
		var chanpindh = $("#chanpindh").val();
		var shiyanlx = $("#shiyanlx").val();
		var fuzher = $("#fuzher").val();
		var shiyandd = $("#shiyandd").val();
		var shemidj = $("#shemidj").val();
		var shiyankssj = $("#shiyankssj").val();
		var yujijssj = $("#yujijssj").val();
		var jieduanlx = $("#jieduanlx").val();
		//var jihuaydl = $("#jihuaydl").val();
		if(renwubh ==null || renwubh == "" ){
			alert("试验任务编号不能为空！");
			$("#renwubh").focus();
    		return false;
		}
		if(chanpindh ==null || chanpindh == "" ){
			alert("产品代号不能为空！");
			$("#chanpindh").focus();
    		return false;
		}
		if(shiyanlx ==null || shiyanlx == "" ){
			alert("试验类型不能为空！");
			$("#shiyanlx").focus();
    		return false;
		}
		if(fuzher ==null || fuzher == "" ){
			alert("负责人不能为空！");
			$("#fuzher").focus();
    		return false;
		}
		if(shiyandd ==null || shiyandd == "" ){
			alert("试验地点不能为空！");
			$("#shiyandd").focus();
    		return false;
		}
		if(shemidj ==null || shemidj == "" ){
			alert("涉密等级不能为空！");
			$("#shemidj").focus();
    		return false;
		}
		if(shiyankssj ==null || shiyankssj == "" ){
			alert("试验开始时间不能为空！");
			$("#shiyankssj").focus();
    		return false;
		}
		if(yujijssj ==null || yujijssj == "" ){
			alert("预计结束时间不能为空！");
			$("#yujijssj").focus();
    		return false;
		}
		if(jieduanlx ==null || jieduanlx == "" ){
			alert("阶段类型不能为空！");
			$("#jieduanlx").focus();
    		return false;
		}
		
		return true;
	}

   //添加设计所
   function selectShejis(){
         if ($("#junyansid").val()==''){
         	alert('请先保存数据！');
         	return;
         }
         var userIDs = "";
         var ids = $("#gridTableShejis").jqGrid('getDataIDs')+"";
         if (ids!=''){
         	 var arrayIDs = ids.split(',');
	         for(var i=0;i<arrayIDs.length;i++){
	         	 var row = jQuery("#gridTableShejis").jqGrid('getRowData',arrayIDs[i]);//获取选中行.
	         	 userIDs+=row.USERID+",";
	         }
	         if (userIDs.length>0){
	         	userIDs = userIDs.substring(0,userIDs.length-1);
	         }
         }
		 var users = window.showModalDialog("<%=request.getContextPath() %>/resource/choose/chooseAllUser.jsp?userid="+userIDs, window, "dialogWidth:930px;status:no;dialogHeight:500px");
   	 	 if (users != null) {
   		    var userIds = [];
            var userNames = [];
            for(var i=0;i<users.length;i++){
               userIds.push(users[i]['userid']);
               userNames.push(users[i]['username']);
            }
            $.ajax({
					type: "POST",
					async: false,//取消异步提交
					url: '<%=request.getContextPath() %>/junyansAction!addJunyansShejis.action?userids='+userIds+'&junyansid='+$("#junyansid").val(),
					dataType: "json",
					success : function(data, textStatus) {  
						if(data.result=='success'){
						    //alert("添加成功！");	
						    gridSearchShejis();									
						}else{
							alert("添加失败，请联系管理员！")
						}
					}
			});
         }
	}
   
   //删除设计所
   function deleteShejis(){
		var ids= $("#gridTableShejis").jqGrid("getGridParam", "selarrrow") + "";
		if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		if(!confirm("是否确认删除？")){
			return false;
		}
		var params = {
					"ids": ids,
					"tableName":"kl_junyans_shejis"
					};  
		var actionUrl = "<%=request.getContextPath() %>/auto!deleteForm.action";  
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      		alert("删除成功！");       
		      		gridSearchShejis();
		      	}else{
		      		alert("删除失败！");
		      	}
		    }  
		});
	}
	
   //刷新设计所
   function gridSearchShejis(){
        jQuery("#gridTableShejis").jqGrid('setGridParam',
              {
                  url:'<%=request.getContextPath() %>/junyansAction!queryJunyansShejis.action?junyansid='+$("#junyansid").val()
              }).trigger("reloadGrid", [{page:1}]); 
   }
   
	
   //选择检测项目
	function selectItem(){
	     if ($("#junyansid").val()==''){
         	alert('请先保存数据！');
         	return;
         }
         
         var toUrl = '<%=request.getContextPath() %>/junyans/choose_project.jsp?junyansid='+$("#junyansid").val()+'&temp='+Math.round(Math.random()*10000);
		 W.$.dialog({
	        title: '选择测试项目',
	        content: 'url:'+ toUrl,
	        okVal: false,//确定按钮文字-->
	        cancelVal: false,//取消按钮文字-->
	        min: true, //是否显示最小化按钮-->
	        max: false,//是否显示最大化按钮-->
	        fixed: false,//开启静止定位-->
	        lock: true,//开启锁屏-->
	        focus: true,//弹出窗口后是否自动获取焦点（4.2.0新增）-->
	        time: null,//设置对话框显示时间-->
	        resize: true,//是否允许用户调节尺寸-->
	        drag: true,//是否允许用户拖动位置-->
	        cache: false,//是否缓存iframe方式加载的窗口内容页
	        width: 1000,
	        height: 500,
	        close: function(){
	        	gridSearchItem();
		    }
		});
         
	}
	
	//删除检测项目及标准
	function deleteItem(){
		var ids= $("#gridTableItem").jqGrid("getGridParam", "selarrrow") + "";
		if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		if(!confirm("是否确认删除？")){
			return false;
		}
		var params = {
					"ids": ids,
					"tableName":"kl_junyans_xm"
					};  
		var actionUrl = "<%=request.getContextPath() %>/auto!deleteForm.action";  
		$.ajax({  
			  url : actionUrl,  
		      type : "post", 
		      data : params,  
		      dataType : "json",  
		      cache : false,  
		      error : function(textStatus, errorThrown) {  
		          alert("系统ajax交互错误: " + textStatus.value);  
		      },  
		      success : function(data, textStatus) {
		      	if(data.result=='success'){
		      		alert("删除成功！");       
		      		gridSearchItem();
		      	}else{
		      		alert("删除失败！");
		      	}
		    }  
		});
	}
	
	//刷新检测项目列表
   function gridSearchItem(){
        jQuery("#gridTableItem").jqGrid('setGridParam',
              {
                  url:'<%=request.getContextPath() %>/junyansAction!queryJunyansItem.action?junyansid='+$("#junyansid").val()
              }).trigger("reloadGrid", [{page:1}]); 
   }
	
	function selectDaihao(){
		var datas = window.showModalDialog("<%=basePath%>/knowledgeManager/selectDaihao.jsp","","dialogWidth=400px;dialogHeight=500px");
		if (datas!=undefined){
			document.getElementById("datatypeid").value = datas.datatypeid;
			document.getElementById("chanpindh").value = datas.daihao;
			document.getElementById("jieduanlx").value = datas.jieduanlx;
		}
	}
	
	 function chooseData(tableName,columnName,cnName,queryColumnCnname,queryColumn,flag){
				var result=window.showModalDialog("<%=request.getContextPath() %>/resource/choose/choose_list.jsp?tableName="+tableName+"&columnName="+columnName+"&cnName="+encodeURIComponent(encodeURIComponent(cnName))+"&queryColumnCnname="+encodeURIComponent(encodeURIComponent(queryColumnCnname))+"&queryColumn="+queryColumn+"&temp="+new Date(), '', "dialogWidth:550px;status:no;dialogHeight:370px");
				if(result){
					result = eval('(' + result + ')');
					if(flag=='shemidj'){
					    document.getElementById("shemidj").value=result['SHEMIDJMC'];
					}
					if(flag=='shiyandd'){
					    document.getElementById("shiyandd").value=result['SHIYANDD'];
					}
				}
     }

   </script>
 	<style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  	
		.formTableNew textarea{border: 1px solid #999;padding: 5px;width: 760px;-moz-border-radius: 3px;border-radius: 3px;margin-bottom: 5px;color: #666;background: url(../images/input_bg.gif) repeat-x top;}
   </style>
  </head>
  
  <body style="overflow-y: scroll;">
  		<form id="pageFrom" action="" enctype="multipart/form-data" method="post">
     	<input type="hidden" id="junyansid" name="junyansid" value="${junyans.id}" />
     	<input type="hidden" id="datatypeid" name="junyans.datatypeid" value="${junyans.datatypeid}" />
  		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
  		    <tr>
  		    	<td align="right">试验任务编号：</td>
  		    	<td colspan="3" align="left">
	  			    <input  type="text"  id="renwubh" maxlength="50" name="junyans.renwubh" 
	  			    style="border: 1px solid #999;height:25px;width: 738px;"  value="${junyans.renwubh}" readonly />
	  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			    </td>
  		    </tr>
  			<tr>
  			  <td align="right">产品代号：</td>
  			  <td align="left">
  			    <input readonly type="text"  id="chanpindh" maxlength="50" name="junyans.chanpindh" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.chanpindh}" />
  			  	<img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  	<img src="web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" onclick="selectDaihao()" />
  			  </td>
  			  <td align="right">试验类型：</td>
  			  <td align="left">
  			     <select id="shiyanlx" name="junyans.shiyanlx" class='easyui-validatebox' style="border: 1px solid #999;height:25px;width:258px;height:30px;" >
 			      <option value="摸底试验" <s:if test='junyans.shiyanlx=="摸底试验"'>selected</s:if>>摸底试验</option>
			 	  <option value="性能攻关试验" <s:if test='junyans.shiyanlx=="性能攻关试验"'>selected</s:if>>性能攻关试验</option>
			 	  <option value="功耗试验" <s:if test='junyans.shiyanlx=="功耗试验"'>selected</s:if>>功耗试验</option>
			 	  <option value="定型试验" <s:if test='junyans.shiyanlx=="定型试验"'>selected</s:if>>定型试验</option>
			 	  <option value="寿命试验" <s:if test='junyans.shiyanlx=="寿命试验"'>selected</s:if>>寿命试验</option>
 			    </select>
 			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			   </td>
  			</tr>
  			<tr>
  			  <td align="right">负责人：</td>
  			  <td align="left">
  			    <input  type="text"  id="fuzher"  name="junyans.fuzher" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.fuzher}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">试验地点：</td>
  			   <td align="left">
  			    <input  type="text" id="shiyandd" maxlength="50" name="junyans.shiyandd" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.shiyandd}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			    <img src="web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" 
  			    onclick="chooseData('DIDIANINFO','ID,SHIYANDD','主键,试验地点','试验地点','SHIYANDD','shiyandd');" />
  			   </td>
  			</tr>
  			<tr>
  			  <td align="right">试验大纲：</td>
  			  <td align="left">
  			  	 <jsp:include page="../fileupload/attachment.jsp?id=${shiyandg}&column=shiyandg&show=n" ></jsp:include>
  			  	 <input type='hidden' name='shiyandg' id='shiyandg' value='${shiyandg}' />
  			  </td>
  			  <td align="right">涉密等级：</td>
  			  <td align="left">
  			    <input  type="text"  id="shemidj" readonly maxlength="50"  name="junyans.shemidj" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.shemidj}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			    <img src="web/images/form_icon_1.gif" style="cursor:hand; vertical-align: middle;" 
  			    onclick="chooseData('KL_SHEMIDJ','ID,SHEMIDJMC','主键,涉密等级','涉密等级','SHEMIDJMC','shemidj');" />
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">试验开始时间：</td>
  			  <td align="left">
  			    <input class="Wdate"  onClick="WdatePicker()"   type="text"  id="shiyankssj" maxlength="50"  name="junyans.shiyankssj" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.shiyankssj}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">预计结束时间：</td>
  			  <td align="left">
  			     <input class="Wdate"  onClick="WdatePicker()" type="text"  id="yujijssj" maxlength="50" name="junyans.yujijssj" 
  			     style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.yujijssj}"/>
  			     <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			</tr>
  			<tr>
  			  <td align="right">阶段类型：</td>
  			  <td align="left">
  			    <input readonly  type="text"  id="jieduanlx" maxlength="50"  name="junyans.jieduanlx" 
  			    style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.jieduanlx}" />
  			    <img src="<%=request.getContextPath() %>/images/xh.png" align="absmiddle"></img>
  			  </td>
  			  <td align="right">计划用弹量：</td>
  			  <td align="left">
  			     <input  type="text"  id="jihuaydl" maxlength="50" name="junyans.jihuaydl" 
  			     style="border: 1px solid #999;height:25px;width: 250px;"  value="${junyans.jihuaydl}" />
  			     
  			  </td>
  			</tr>
		    <tr>
		    <td colspan='4' align='center'>
		      <div id='tt1' class='easyui-tabs' style='width:750px;height:320px'>
		        <div title='设计室人员' style='padding:10px'>
		          <input id='btnselectShejis' type='button'  value='选择人员' onclick="selectShejis()" class='form_bt_orange'/>&nbsp;
				  <input id='btndeleteShejis' type='button'  value='删 除' onclick="deleteShejis()" class='form_bt_orange'/>
                  <table id="gridTableShejis"></table>
                  <div id="gridPagerShejis"></div></div>
                 
                <div title='测试项目' style='padding:10px'>
                  <input id='btnselectItem' type='button'  value='选择项目' onclick="selectItem()" class='form_bt_orange'/> &nbsp;
			      <input id='btndeleteItem' type='button'  value='删 除' onclick="deleteItem()" class='form_bt_orange'/> &nbsp;
                  <table id="gridTableItem"></table>
                  <div id="gridPagerItem"></div>
				 </div>
			</td>
		</tr>
		</table>
		<input type="hidden" id="junyansid" name="junyansid" value="${junyans.id}" />
		<input type='hidden' id='flowid' name='flowid' value='${flowid}'>
		<input type='hidden' id='stateid' name='stateid' value='${stateid}'>
		<input type='hidden' id='nextUserIds' name='nextUserIds' >
		<input type='hidden' id='nextUserNames' name='nextUserNames' >
		${steptcontent }
		<table width="100%" border="0" align="center" class="formTableNew">
		  <tr>
			<td align="center">
				<input id="saveBtn" type="button" value="保 存" class="form_bt_orange" />
		    	<input id="submitBtn" type="button" value="提 交" class="form_bt_orange" />
		    	<input  id="closeBtn" type="button" value="取 消" class="form_bt_grey" />
		    </td>
		  </tr>
		  <tr>
		  	<td>&nbsp;&nbsp; </td>
		  </tr>
		</table>
	<!--表单结束-->
	</form>
  </body>
</html>
